package com.redsoil.house.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.redsoil.house.R;
import com.redsoil.house.model.bean.PropertyLeaseVO;
import com.redsoil.house.model.http.api.ApiConstants;
import com.zhy.autolayout.AutoLinearLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by weidingqiang on 2019/1/24.
 * lan com
 */

public class PropertyAdView extends AutoLinearLayout {

    private ImageView image_1;
    private ImageView image_2;
    private ImageView image_3;
    private ImageView image_4;
    private ImageView image_5;
    private ImageView image_6;

    private List<ImageView> viewLists;

    public PropertyAdView(Context context) {
        this(context,null);
    }

    public PropertyAdView(Context context, AttributeSet attrs) {
        super(context, attrs);

        LayoutInflater inflater = LayoutInflater.from(context);
        inflater.inflate(R.layout.property_ad_view, this, true);

        image_1 = (ImageView) this.findViewById(R.id.image_1);
        image_2 = (ImageView) this.findViewById(R.id.image_2);
        image_3 = (ImageView) this.findViewById(R.id.image_3);
        image_4 = (ImageView) this.findViewById(R.id.image_4);
        image_5 = (ImageView) this.findViewById(R.id.image_5);
        image_6 = (ImageView) this.findViewById(R.id.image_6);

        viewLists = new ArrayList<ImageView>();

        viewLists.add(image_1);
        viewLists.add(image_2);
        viewLists.add(image_3);
        viewLists.add(image_4);
        viewLists.add(image_5);
        viewLists.add(image_6);

    }

    public void setData(List<PropertyLeaseVO.AdsBean> list){
        for (int i=0;i<viewLists.size();i++){
            ImageView imageView = viewLists.get(i);
            try {
                PropertyLeaseVO.AdsBean adsBean = list.get(i);
                Glide.with(getContext())
                        .load(ApiConstants.STATIC_FILE+adsBean.getPicturePath())
                        .centerCrop()
                        .into(imageView);
            }catch (Exception ex){
                imageView.setVisibility(INVISIBLE);
            }
        }
    }

}
